Skip to content

[hi-rachel] Week 8 solutions #1503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 24, 2025
Merged

[hi-rachel] Week 8 solutions #1503

merged 5 commits into from
May 24, 2025

Conversation

hi-rachel
Copy link
Contributor

@hi-rachel hi-rachel commented May 20, 2025

답안 제출 문제

작성자 체크 리스트

  • 우측 메뉴에서 PR을 Projects에 추가해주세요.
  • Projects의 오른쪽 버튼(▼)을 눌러 확장한 뒤, Week를 현재 주차로 설정해주세요.
  • 문제를 모두 푸시면 프로젝트에서 StatusIn Review로 설정해주세요.
  • 코드 검토자 1분 이상으로부터 승인을 받으셨다면 PR을 병합해주세요.

검토자 체크 리스트

Important

본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!

  • 바로 이전에 올라온 PR에 본인을 코드 리뷰어로 추가해주세요.
  • 본인이 검토해야하는 PR의 답안 코드에 피드백을 주세요.
  • 토요일 전까지 PR을 병합할 수 있도록 승인해주세요.

@hi-rachel hi-rachel moved this from Solving to In Review in 리트코드 스터디 4기 May 23, 2025
Copy link
Contributor

@seungriyou seungriyou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

문제마다 접근한 방법, 시간/공간 복잡도, 코멘트가 잘 정리되어 있어 코드를 더 잘 이해할 수 있었던 것 같아요! 이번 주도 고생 많으셨습니다~ 새로운 한 주도 화이팅! 💪🏻

그래프의 깊은 복사 반환해라

TC: O(V + E), V: 노드의 수, E: 이웃의 수
SC: O(V + E)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

코드가 매우 직관적이고 알아보기 쉽게 작성된 것 같아요 🤩

다만 clones에는 노드의 개수만큼 복제 노드가 저장되고, DFS의 경우 call stack이 최대 노드의 개수만큼, BFS의 경우 queue가 최대 노드의 개수만큼 커질 것이기 때문에 공간 복잡도는 O(V) 가 될 것 같습니다..!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seungriyou 복제된 그래프의 전체 구조까지 포함한 공간을 고려하면
O(V + E)가 될 수 있을 것 같습니다!

if text1[i - 1] == text2[j - 1]:
dp[i][j] = dp[i - 1][j - 1] + 1 # 두 문자가 같으면, 이전 상태 + 1
else:
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) # 다르면, 하나 줄인 상태 중 최댓값 선택
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저 또한 rachel 님처럼 처음에 2D DP(O(m * n) space)로 접근했었는데요, 2D DP에서 매 단계마다 dp[i - 1] row와 dp[i] row만 확인하기 때문에 이를 1D DP(O(n) space)로 공간 복잡도를 최적화 할 수 있다는 점을 알게 되어 공유드립니다!

dp[i - 1] row와 dp[i] row를 각각 길이가 n + 1인 리스트prevcurr로 두고, 이를 모든 row 마다 번갈아 가며 사용하면 최적화가 가능하다고 해요~!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seungriyou 좋은 리뷰 감사합니다. 다시 풀때 최적화 해보도록 하겠습니다!

항상 32비트이므로 상수 시간, 상수 공간
TC: O(1)
SC: O(1)
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여러 방법으로 풀이해주셔서 많은 참고가 되었습니다! 😆

@hi-rachel hi-rachel merged commit ce12735 into DaleStudy:main May 24, 2025
1 check passed
@github-project-automation github-project-automation bot moved this from In Review to Completed in 리트코드 스터디 4기 May 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

2 participants